//
// Created on 2024/7/31.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be
// found, please include "napi/native_api.h".

#ifndef ARKUI_C_API_NATIVEENTRY_H
#define ARKUI_C_API_NATIVEENTRY_H

#include "napi/native_api.h"
#include "src/ArkUIBaseNode.h"
#include <js_native_api_types.h>
#include <memory>

namespace NativeModule {

napi_value CreateNativeRoot(napi_env env, napi_callback_info info);

napi_value DestroyNativeRoot(napi_env env, napi_callback_info info);

std::shared_ptr<ArkUIBaseNode> CreateRootNode(std::vector<std::string> code);

class NativeEntry {
    std::shared_ptr<ArkUIBaseNode> root_;
    ArkUI_NodeContentHandle handle_;

public:
    static NativeEntry *GetInstance() {
        static NativeEntry nativeEntry;
        return &nativeEntry;
    }

    void SetContentHandle(ArkUI_NodeContentHandle handle) { handle_ = handle; }

    void SetRootNode(std::shared_ptr<ArkUIBaseNode> &baseNode) {
        root_ = baseNode;
        OH_ArkUI_NodeContent_AddNode(handle_, root_->GetHandle());
    }

    void DisposeRootNode() {
        OH_ArkUI_NodeContent_RemoveNode(handle_, root_->GetHandle());
        root_.reset();
    }
};

} // namespace NativeModule


#endif // ARKUI_C_API_NATIVEENTRY_H
